<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:fo="http://www.w3.org/1999/XSL/Format" version="1.0">

    <xsl:template name="component.title.chapterlike"> 
        <xsl:param name="bigtext.size">1.5em</xsl:param>
        <xsl:param name="node" select="."/>
        <xsl:variable name="id">
            <xsl:call-template name="object.id">
                <xsl:with-param name="object" select="$node"/>
            </xsl:call-template>
        </xsl:variable>
        
        <fo:block start-indent="0pt">
            <!-- logo -->
            <xsl:call-template name="gl.logo">
                <xsl:with-param name="size">0.75in</xsl:with-param>
            </xsl:call-template>
        </fo:block>
        
        <xsl:element name="fo:block" use-attribute-sets="component.title.properties">

            <xsl:element name="fo:block" use-attribute-sets="rule.after.title.properties">
                <xsl:attribute name="id">
                    <xsl:value-of select="$id"/>
                </xsl:attribute>
                <xsl:attribute name="text-align">end</xsl:attribute>
                <xsl:attribute name="line-height"><xsl:value-of select="$bigtext.size"/></xsl:attribute>
                
                <xsl:element name="fo:inline">
                    <xsl:attribute name="color"><xsl:value-of select="$title.font.color"/></xsl:attribute>
                    <!--xsl:attribute name="alignment-adjust">
                        <xsl:value-of select="concat('- ',$bigtext.size,' div 2')"/>
                    </xsl:attribute-->
                    <xsl:call-template name="gentext">
                        <xsl:with-param name="key">
                            <xsl:choose>
                                <xsl:when test="$node/self::chapter">chapter</xsl:when>
                                <xsl:when test="$node/self::article">chapter</xsl:when>
                                <xsl:when test="$node/self::appendix">appendix</xsl:when>
                                <xsl:when test="$node/self::preface">preface</xsl:when>
                                <xsl:when test="$node/self::glossary">glossary</xsl:when>
                                <xsl:when test="$node/self::index">index</xsl:when>
                            </xsl:choose>
                        </xsl:with-param>
                    </xsl:call-template>
                    <xsl:text> </xsl:text>
                    <xsl:element name="fo:inline">
                        <xsl:attribute name="font-size"><xsl:value-of select="$bigtext.size"/></xsl:attribute>
                        <!--xsl:text>0</xsl:text-->
                        <xsl:apply-templates select="$node" mode="label.markup"/>
                    </xsl:element>
                </xsl:element>
            </xsl:element>

            <xsl:element name="fo:block">
                <xsl:attribute name="color"><xsl:value-of select="$title.font.color"/></xsl:attribute>
                <xsl:attribute name="space-before">0.5em</xsl:attribute>
                <xsl:apply-templates select="$node" mode="title.markup"/>
            </xsl:element>

        </xsl:element>
    </xsl:template>

    <xsl:template match="chapter|appendix|preface|article">
        <xsl:variable name="id">
            <xsl:call-template name="object.id"/>
        </xsl:variable>
        
        <xsl:variable name="master-reference">
            <xsl:call-template name="select.pagemaster"/>
        </xsl:variable>
        
        <fo:page-sequence hyphenate="{$hyphenate}"
            master-reference="{$master-reference}">
            <xsl:attribute name="language">
                <xsl:call-template name="l10n.language"/>
            </xsl:attribute>
            <xsl:attribute name="format">
                <xsl:call-template name="page.number.format">
                    <xsl:with-param name="master-reference" select="$master-reference"/>
                </xsl:call-template>
            </xsl:attribute>
            <xsl:attribute name="initial-page-number">
                <xsl:call-template name="initial.page.number">
                    <xsl:with-param name="master-reference" select="$master-reference"/>
                </xsl:call-template>
            </xsl:attribute>
            
            <xsl:attribute name="force-page-count">
                <xsl:call-template name="force.page.count">
                    <xsl:with-param name="master-reference" select="$master-reference"/>
                </xsl:call-template>
            </xsl:attribute>
            
            <xsl:attribute name="hyphenation-character">
                <xsl:call-template name="gentext">
                    <xsl:with-param name="key" select="'hyphenation-character'"/>
                </xsl:call-template>
            </xsl:attribute>
            <xsl:attribute name="hyphenation-push-character-count">
                <xsl:call-template name="gentext">
                    <xsl:with-param name="key" select="'hyphenation-push-character-count'"/>
                </xsl:call-template>
            </xsl:attribute>
            <xsl:attribute name="hyphenation-remain-character-count">
                <xsl:call-template name="gentext">
                    <xsl:with-param name="key" select="'hyphenation-remain-character-count'"/>
                </xsl:call-template>
            </xsl:attribute>
            
            <xsl:apply-templates select="." mode="running.head.mode">
                <xsl:with-param name="master-reference" select="$master-reference"/>
            </xsl:apply-templates>
            
            <xsl:apply-templates select="." mode="running.foot.mode">
                <xsl:with-param name="master-reference" select="$master-reference"/>
            </xsl:apply-templates>
            
            <fo:flow flow-name="xsl-region-body">
                <xsl:call-template name="set.flow.properties">
                    <xsl:with-param name="element" select="local-name(.)"/>
                    <xsl:with-param name="master-reference" select="$master-reference"/>
                </xsl:call-template>
                
                <fo:block id="{$id}">
                    <xsl:choose>
                        <xsl:when test="self::chapter">
                            <xsl:call-template name="chapter.titlepage"/>
                        </xsl:when>
                        <xsl:when test="self::preface">
                            <xsl:call-template name="preface.titlepage"/>
                        </xsl:when>
                        <xsl:when test="self::appendix">
                            <xsl:call-template name="appendix.titlepage"/>
                        </xsl:when>
                        <xsl:when test="self::article">
                            <xsl:call-template name="article.titlepage"/>
                        </xsl:when>
                        <xsl:when test="self::index">
                            <xsl:call-template name="index.titlepage"/>
                        </xsl:when>
                        <xsl:when test="self::glossary">
                            <xsl:call-template name="glossary.titlepage"/>
                        </xsl:when>
                    </xsl:choose>
                </fo:block>
                
                <xsl:apply-templates select="abstract"/>
                
                <xsl:variable name="toc.params">
                    <xsl:call-template name="find.path.params">
                        <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
                    </xsl:call-template>
                </xsl:variable>
                
                <xsl:if test="contains($toc.params, 'toc')">
                    <xsl:call-template name="component.toc">
                        <xsl:with-param name="toc.title.p" 
                            select="contains($toc.params, 'title')"/>
                    </xsl:call-template>
                    <xsl:call-template name="component.toc.separator"/>
                </xsl:if>
                
                <xsl:apply-templates select="node()[not(self::abstract)]"/>
                
            </fo:flow>
        </fo:page-sequence>
    </xsl:template>
    
</xsl:stylesheet>
